package controller;

import model.Supplier;
import model.SupplierContainer;

public class SupplierController {
	private static SupplierController supplierController = null;
	private static SupplierContainer supplierContainer; 
	
	private SupplierController(){
		supplierContainer = SupplierContainer.getInstance();
	}
	
	public static SupplierController getInstance(){
		if(supplierController == null){
			supplierController = new SupplierController();
		}
		return supplierController;
	}

	public int getCvrNr(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getCvrNr();
	}
	
	public void setCvrNr(int cvrNr, int newCvrNr){
		supplierContainer.findSupplier(cvrNr).setCvrNr(newCvrNr);
	}

	public String getCompanyName(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getCompanyName();
	}
	
	public void setCompanyName(int cvrNr, String companyName){
		supplierContainer.findSupplier(cvrNr).setCompanyName(companyName);
	}

	public String getDescription(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getDescription();
	}
	
	public void setDescription(int cvrNr, String description){
		supplierContainer.findSupplier(cvrNr).setDescription(description);
	}

	public String getEmail(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getEmail();
	}
	
	public void setEmail(int cvrNr, String email){
		supplierContainer.findSupplier(cvrNr).setEmail(email);
	}
	
	public int getPhone(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getPhone();
	}
	
	public void setPhone(int cvrNr, int phone){
		supplierContainer.findSupplier(cvrNr).setPhone(phone);
	}

	public String getAddress(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getAddress();
	}
	
	public void setAddress(int cvrNr, String address){
		supplierContainer.findSupplier(cvrNr).setAddress(address);
	}
	
	public String getCity(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getCity();
	}
	
	public void setCity(int cvrNr, String city){
		supplierContainer.findSupplier(cvrNr).setCity(city);
	}

	public int getPostalCode(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getPostalCode();
	}
	
	public void setPostalCode(int cvrNr, int postalCode){
		supplierContainer.findSupplier(cvrNr).setPostalCode(postalCode);
	}
	
	public double getDiscount(int cvrNr){
		return supplierContainer.findSupplier(cvrNr).getDiscount();
	}
	
	public void setDiscount(int cvrNr, double discount){
		supplierContainer.findSupplier(cvrNr).setDiscount(discount);
	}
	
	//** Creates a Supplier object */
	public void createSupplier(int cvrNr, String companyName, String description, String email, int phone, String address, String city, int postalCode, double discount){
		supplierContainer.addSupplier(new Supplier(cvrNr, companyName, description, email, phone, address, city, postalCode, discount));
	}
	
	//** Updates a Supplier object */
	public void updateSupplier(int cvrNr, String companyName, String description, String email, int phone, String address, String city, int postalCode, double discount){
		Supplier supplier = supplierContainer.findSupplier(cvrNr);
		supplier.setCvrNr(cvrNr);
		supplier.setCompanyName(companyName);
		supplier.setDescription(description);
		supplier.setEmail(email);
		supplier.setPhone(phone);
		supplier.setAddress(address);
		supplier.setCity(city);
		supplier.setPostalCode(postalCode);
		supplier.setDiscount(discount);
	}
}
